package com.hengtuo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hengtuo.base.BaseFragment;
import com.hengtuo.kaiyuanzhongguo.R;
import com.hengtuo.vo.Eveunt;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by Administrator on 2016/5/15.
 */
public class NeardAdapter extends BaseAdapter {

    private Context context;
    private List<Eveunt> list;

    public NeardAdapter(Context context, List<Eveunt> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder vh = null;
        if(convertView==null){
            vh = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_near,null);
            vh.image = (ImageView) convertView.findViewById(R.id.adapter_near_image);
            vh.title = (TextView)convertView.findViewById(R.id.adapter_near_title);
            vh.time = (TextView)convertView.findViewById(R.id.adapter_near_time);
            vh.address = (TextView)convertView.findViewById(R.id.adapter_near_address);
            convertView.setTag(vh);
        }else{
            vh = (ViewHolder)convertView.getTag();
        }

        ImageLoader.getInstance().displayImage(list.get(position).getCover(),vh.image);
        vh.title.setText(list.get(position).getTitle());
        vh.time.setText(""+list.get(position).getCreateTime());
        vh.address.setText(list.get(position).getSpot());

        return convertView;
    }

    class ViewHolder{

        ImageView image;
        TextView title,time,address;

    }

}
